package com.codeyang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codeyang.domain.ProdComm;
import com.codeyang.dto.ProdCommDto;
import com.codeyang.service.ProdCommService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述: TO-删除标志-DO
 *
 * @author CodeYang_Site
 * @version 2021/5/25 0:29
 */
@Api(tags = "商品评论管理接口")
@RestController
@RequestMapping("prod/prodComm")
public class ProdCommController {

    @Autowired
    private ProdCommService prodCommService;

    /**
     * 分页查询商品评论管理列表查询
     * @param page
     * @param prodComm
     * @return
     */
    @ApiOperation("分页查询商品评论管理")
    @PreAuthorize("hasAnyAuthority('prod:prodComm:page')")
    @GetMapping("page")
    public ResponseEntity<Page<ProdComm>> page(Page<ProdComm> page,ProdComm prodComm) {
        Page<ProdComm> prodCommPage = prodCommService.findPageCommPage(page,prodComm);
        return ResponseEntity.ok(prodCommPage);

    }


    /**
     * 根据商品的id分页查询评论
     * @param prodId
     * @param size
     * @param current
     * @param evaluate
     * @return
     */
    @GetMapping("prodComm/prodCommPageByProd")
    @ApiOperation("根据商品的id分页查询评论")
    public ResponseEntity<Page<ProdComm>> prodCommPageByProd(@RequestParam Long prodId, Integer size, Integer current, Integer evaluate) {
        Page<ProdComm> prodCommPage = prodCommService.prodCommPageByProd(prodId, size, current, evaluate);
        return ResponseEntity.ok(prodCommPage);
    }






    // 根据商品的id获取评论总览  好评率 好评数 中评数 差评数 总评数 有图

    @GetMapping("prodComm/prodCommData")
    @ApiOperation("根据商品id查询商品评论总览")
    public ResponseEntity<ProdCommDto> prodCommData(@RequestParam Long prodId) {
        ProdCommDto prodCommDto = prodCommService.findProdCommDtoByProdId(prodId);
        return ResponseEntity.ok(prodCommDto);
    }





}
